<?php
class RM_Discounts_Rule_Duration extends RM_Discounts_Rule {
    public function isMatched(RM_Reservation_Details $detail){
        $discountPeriod = new RM_Reservation_Period(
            new RM_Date(strtotime($this->_discount->start_date)),
            new RM_Date(strtotime($this->_discount->end_date))
        );

        $intersection = $discountPeriod->getIntersection($detail->getPeriod());
        if ($intersection == null) return false;

        $minDurationDays = $this->_value;
        return ($minDurationDays <= $intersection->getLength());
    }
}
